using System.ServiceModel;
using WcfTest.GuiClient.Services.Common;
using WcfTest.GuiClient.TalkingServiceProxy;
using ITalkingServiceProxy = WcfTest.GuiClient.TalkingServiceProxy.ITalkingService;

namespace WcfTest.GuiClient.Services.Impl
{
	internal class TalkingService : AbstractAsyncService, ITalkingService
	{
		#region Fields

		private readonly ITalkingServiceProxy proxy;

		#endregion Fields

		#region Constructors

		public TalkingService(string talkingServiceUrl)
		{
			var client = new TalkingServiceClient();
			client.Endpoint.Address = new EndpointAddress(talkingServiceUrl);

			proxy = client;
		}

		#endregion Constructors

		#region ITalkingService implementation

		public void BeginSaying(ServiceSuccessCallback<string> successCallback, ServiceErrorCallback errorCallback)
		{
			DoRequest(Say, successCallback, errorCallback);
		}

		#endregion ITalkingService implementation

		#region Helpers

		private string Say()
		{
			return proxy.Say();
		}

		#endregion Helpers
	}
}